﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WebApplication1.Classes;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections.Generic;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        private string Сon = @"Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=Test;
Integrated Security=True;Pooling=False";
        private int value;
        private int role;
        private string name;
        private string surname;
        private int id;
        //public static List<Contract> conList;
        

        protected void Connection(string c)
        {
            try
            {
                SqlConnection connection = new SqlConnection(c);
                connection.Open();
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Ошибка при установлении соединения: " + ex.Message);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Label3.Visible = true;
            id=Convert.ToInt32(Session["id"]);
            role = Convert.ToInt32(Session["role"]);
            name = Convert.ToString(Session["name"]);
            surname = Convert.ToString(Session["surname"]);
            Session.Remove("id");
            Session.Remove("role");
            Session.Remove("name");
            Session.Remove("surname");
            Session["id"] = id;
            Session["name"] = name;
            Session["surname"] = surname;
            Session["role"] = role;
            Label3.Text = ("Здравствуйте, " + name + " " + surname + "!!!");
            if (role == 1) {
                Button3.Visible = true;
                GridView1.AutoGenerateEditButton = true;
                GridView1.AutoGenerateDeleteButton = true;
            }
            if (role == 2)
            {
                Button4.Visible = true;
                Button3.Visible = true;
                GridView1.AutoGenerateEditButton = true;
                GridView1.AutoGenerateDeleteButton = true;
            }
        }

        

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            value = Convert.ToInt32(GridView1.SelectedDataKey.Value);
            Session["con"] = value;
            Server.Transfer("details.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Server.Transfer("client.aspx");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Server.Transfer("Users.aspx");
        }
    }
}
